package com.ruoyi.system.domain.dto;

import cn.hutool.core.collection.CollectionUtil;
import com.ruoyi.common.constant.UserConstants;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;
import java.util.Objects;

public class AmsFirstAidDto {

    @Data
    @ApiModel("FirstAidDto-SaveAidRecord")
    public static class SaveAidRecord {
        @Data
        @ApiModel("题目code和答案")
        public static class CodeAndAnswer{
            @NotBlank
            @ApiModelProperty("code")
            private String questionCode;
            @Size(max = 6,message = "答案不能超过6个")
            @ApiModelProperty("答案")
            private List<String> answer;
            @ApiModelProperty("发生时间")
            private Date time;

            public String getAnswerString(){
                if(CollectionUtil.isEmpty(answer)){
                    return "";
                }
                return CollectionUtil.join(answer, UserConstants.ANSWER_JOIN_STRING);
            }

            @Override
            public boolean equals(Object o) {
                if (this == o) {
                    return true;
                }
                if (o == null || getClass() != o.getClass()) {
                    return false;
                }
                CodeAndAnswer codeAndAnswer = (CodeAndAnswer) o;
                return Objects.equals(questionCode, codeAndAnswer.questionCode);
            }

            @Override
            public int hashCode() {
                return Objects.hash(this.questionCode);
            }
        }

        @NotNull(message = "档案ID不能为空")
        @ApiModelProperty("档案ID")
        private Long firstAidId;
        @ApiModelProperty("code和答案")
        private List<CodeAndAnswer> codeAndAnswerList;
        @ApiModelProperty("数据来源，客户端不需要传值")
        private Byte sourceType;
        @ApiModelProperty("数据来源，客户端不需要传值")
        private String sourceId;


    }
}
